package com.laoyao.comm.config;

import com.jfinal.aop.Interceptor;

import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.laoyao.util.abc;

public class WeiXLanJie implements Interceptor {

	public void intercept(Invocation inv) {
		System.out.println("Before invoking " + inv.getActionKey());
		String u = inv.getController().getSessionAttr("openId");
		Controller controller = inv.getController();
		String str = controller.getRequest().getQueryString();
		String url = inv.getActionKey() + "?" + str;
		if (str == null || str.equals("null")) {
			url = inv.getActionKey() + "?a=laoyao";
		}
		//System.out.println("u="+u);
		if (u == null || u.trim().equals("")) {
//			System.out.println("===url====" + url);
//			
//			str = abc
//					.urlEncodeUTF8("http://wwww.taojinshang.cn/taojin/auth/?dist="
//							+ url);
//			String myurl = "https://open.weixin.qq.com/connect/oauth2/authorize?"
//					+ "appid="
//					+ PropKit.get("appid")
//					+ "&redirect_uri="
//					+ str
//					+ "&response_type=code"
//					+ "&scope=snsapi_base"
//					+ "&state=1"
//					+ "#wechat_redirect";
//			System.out.println("===" + myurl + "=========================");
//			inv.getController().redirect(myurl);
			inv.getController().setSessionAttr("openId", "ohcgww_Npy-X4P92rIhnmbWtXTBk");
			inv.invoke();

		}  else {
			inv.invoke();
		}

	}

}
